home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / Development Tools & Languages / Bits o' MacApp Code / Auto Center View / TAutoCenterView.cp next >
Encoding:
Text File  |  1993-06-10  |  1017 b   |  31 lines  |  [TEXT/MPS ]

  1. #include "MacApp.h"
  2. #include <TAutoCentedView.h>
  3.  
  4. //----------------------------------------------------------------------------------------
  5. // TAutoCenterView::SuperViewChangedFrame: 
  6. //----------------------------------------------------------------------------------------
  7. #pragma segment MAViewNonRes
  8. pascal void TAutoCenterView::SuperViewChangedFrame(const VRect& oldFrame,
  9.                                             const VRect& newFrame,
  10.                                             Boolean invalidate)
  11. {
  12.     VRect    myExtent;
  13.     
  14.     inherited::SuperViewChangedFrame(oldFrame,newFrame,invalidate);
  15.     
  16.     GetFrame(myExtent);                        // in superview coordinates
  17.     long myWidth = myExtent.GetLength(hSel);    // get our width
  18.     long hisWidth = newFrame.GetLength(hSel);    // get the superview's new width
  19.     
  20.     if(myWidth < hisWidth) {
  21.         long newLeft = (hisWidth - myWidth) / 2;
  22.         myExtent.left = newLeft;
  23.         myExtent.right = myExtent.left + myWidth;
  24.     }
  25.     else {    // if the super view is too small, move all the way left
  26.         myExtent.left = 0;
  27.         myExtent.right = myWidth;
  28.     }
  29.     SetFrame(myExtent,invalidate);
  30. }
  31.